/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.fd.controller;

import com.xy.biz.fd.client.DocumentCodeRuleClient;
import com.xy.biz.fd.domain.bo.DocumentBO;
import com.xy.biz.fd.domain.converter.DocumentConverter;
import com.xy.biz.fd.domain.req.documentCode.GetDocumentByCodeRequest;
import com.xy.biz.fd.domain.req.documentCode.GetDocumentCodeRuleRequest;
import com.xy.biz.fd.domain.resp.GetDocumentCodeRuleResponse;
import com.xy.biz.fd.domain.resp.GetDocumentCodeRuleResponse1;
import com.xy.biz.fd.domain.resp.GetDocumentResponse;
import com.xy.biz.fd.service.DocumentCodeRuleService;
import com.xy.lang.domain.Result;
import com.xy.lang.validation.annotation.Validatable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 *
 * @author zsp
 * @date 2021-4-29
 */
@Api(tags = "文件编号服务")
@Slf4j
@RestController
@RequestMapping("/api/fd/document_code")
public class DocumentCodeRuleController implements DocumentCodeRuleClient {

    @Autowired
    private DocumentCodeRuleService documentCodeRuleService;

    @Validatable
    @PostMapping(value = "/get_code")
    public Result<GetDocumentCodeRuleResponse> getCode(@RequestBody GetDocumentCodeRuleRequest request) {
        return Result.success(GetDocumentCodeRuleResponse.builder().code(documentCodeRuleService.getCode(request)).build());
    }

    @ApiOperation(value = "获取文件编号")
    @Validatable
    @PostMapping(value = "/generate_code")
    public Result<GetDocumentCodeRuleResponse> generateCode(@RequestBody GetDocumentCodeRuleRequest request) {
        return Result.success(GetDocumentCodeRuleResponse.builder().code(documentCodeRuleService.generateCode(request)).build());
    }

    @Override
    @ApiOperation(value = "获取文件编号信息")
    @Validatable
    @PostMapping(value = "/get_code_info")
    public Result<GetDocumentCodeRuleResponse1> getCodeInfo(@RequestBody GetDocumentCodeRuleRequest request) {
        return documentCodeRuleService.getCodeInfo(request);
    }

    @Override
    @ApiOperation(value = "通过文件编号获取文件")
    @Validatable
    @PostMapping(value = "/get_document_by_code")
    public Result<GetDocumentResponse> getDocumentByCode(@RequestBody GetDocumentByCodeRequest request) {
        return documentCodeRuleService.getDocumentByCode(request);
    }

    @ApiOperation(value = "判断文件编号是否存在")
    @Validatable
    @PostMapping(value = "/get_document_code_is_existed")
    public Result<Boolean> getDocumentCodeIsExisted(@RequestBody GetDocumentByCodeRequest request) {
        return documentCodeRuleService.getDocumentCodeIsExisted(request);
    }

}
